<?php

    $menu = array(
        '/'         => array(
            'label' => 'Nalozi',
            'sub'   => array( '/orders/create' => '+')
        ),
        '/models'   => 'Telefoni',
        '/stores'   => array(
            'label' => 'Prodavnice',
            'role'  => 'admin'
        ),
        '/users'   => array(
            'label' => 'Korisnici',
            'role'  => 'admin'
        )
    );
    $user  = $this->Session->read('CurrentUser');
?>
<ul>
<? foreach($menu as $link => $item): 
    
    $active = is_active($link, $this->params);
    $label  = $item;
    $sub    = false;
    $role   = false;
    
    if (is_array($item)) {
        $label = $item['label'];
        
        if (! empty($item['sub'])) {
            $sub = $item['sub'];
        }
        
        if (! empty($item['role'])) {
            $role = $item['role'];
        }
    }
    
    if ($role && $user['User']['role']!=$role) {
        continue;
    }

    ?><li<?= $active ? ' class="active"' : ''?>>
        
        <? if($sub): ?>
            <span class="sub">
            <? foreach($sub as $sublink=>$sublabel): ?>
                <?= $this->Html->link($sublabel, $sublink, array('class'=>'sublink')) ?>
            <? endforeach ?>
        <? endif ?>
        
        <? if($active): ?>
            <strong><?= $label ?></strong>
        <? else: ?>
            <?= $this->Html->link($label, $link) ?>
        <? endif; ?>
        
        <? if($sub): ?></span><? endif ?>
    </li>
<? endforeach; ?>
<li class="right"><?= $this->element('storeSelect') ?></li>
<li class="right"><?= $this->Html->link("Izlaz (" . $this->Session->read("Auth.User.username") . ")", '/users/logout') ?></li>
</ul>